import 'package:collection/collection.dart';

class ObjList {
  ObjList({
    required this.total,
    required this.list,
  });

  factory ObjList.fromJson(Map json) {
    final list = json['list'];
    return ObjList(
      total: json['total'],
      list: list,
    );
  }

  final int total;
  final List list;

  Map<String, dynamic> toJson() {
    return {
      'total': total,
      'list': list,
    };
  }

  ObjList copyWith({
    int? total,
    List? list,
  }) {
    return ObjList(
      total: total ?? this.total,
      list: list ?? this.list,
    );
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is ObjList &&
          runtimeType == other.runtimeType &&
          total == other.total &&
          const DeepCollectionEquality().equals(list, other.list);

  @override
  int get hashCode => Object.hashAll([
        total,
        const DeepCollectionEquality().hash(list),
      ]);
}

class CityModel {
  String code;
  String name;
  List<CityModel> children;

  CityModel({
    required this.code,
    required this.name,
    required this.children,
  });

  factory CityModel.fromJson(Map<String, dynamic> json) {
    final di = json['children'];
    return CityModel(
      code: json['code'],
      name: json['name'],
      children: di is List ? di.map((e) => CityModel.fromJson(e)).toList() : [],
    );
  }
}

class OrganizationModel {
  final String name;
  final double score;
  final int staffCount;
  final int customerCount;
  final int naturalPersonCount;
  final String establishDate;
  final String legalRepresentative;
  final String address;

  OrganizationModel({
    required this.name,
    required this.score,
    required this.staffCount,
    required this.customerCount,
    required this.naturalPersonCount,
    required this.establishDate,
    required this.legalRepresentative,
    required this.address,
  });

  factory OrganizationModel.fromJson(Map<String, dynamic> json) {
    return OrganizationModel(
      name: json['name'],
      score: json['score'].toDouble(),
      staffCount: json['staffCount'],
      customerCount: json['customerCount'],
      naturalPersonCount: json['naturalPersonCount'],
      establishDate: json['establishDate'],
      legalRepresentative: json['legalRepresentative'],
      address: json['address'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'name': name,
      'score': score,
      'staffCount': staffCount,
      'customerCount': customerCount,
      'naturalPersonCount': naturalPersonCount,
      'establishDate': establishDate,
      'legalRepresentative': legalRepresentative,
      'address': address,
    };
  }
}
